package com.google.code.mamule.integration;

import com.google.common.base.Objects;

import java.util.Locale;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * Created with IntelliJ IDEA. User: borck_000 ; Date: 12/22/13 ; Time: 11:50 PM
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Message {

  public static Message info(String text, Object... args) {
    return new Message(Type.INFO, String.format(Locale.ENGLISH, text, args));
  }

  public static Message error(Throwable cause) {
    return new Message(Type.ERROR, cause.getMessage());
  }

  public static Message error(String text, Object... args) {
    return new Message(Type.ERROR, String.format(Locale.ENGLISH, text, args));
  }

  public static enum Type {
    INFO, ERROR;
  }

  private final String message;
  private final Type type;

  private Message() {
    this(Type.ERROR, "jaxb created");
  }

  public Message(final Type type, final String message) {
    this.message = message;
    this.type = type;
  }

  @Override
  public String toString() {
    return Objects.toStringHelper(this)
        .add("message", message)
        .add("type", type)
        .toString();
  }

  public String getMessage() {
    return message;
  }

  public Type getType() {
    return type;
  }
}
